<template>
    <div class="topic_list">
        <div class="screen">
            <el-select v-model="type_id" filterable placeholder="请选择课题分类">
                <el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
            <el-select v-model="year" filterable placeholder="请选择课题年份">
                <el-option v-for="item in yearList" :key="item" :label="item" :value="item" />
            </el-select>
        </div>
        <div class="list">
            <el-table :data="topicList" stripe style="width: 100%">
                <el-table-column prop="id" label="ID" width="80" />
                <el-table-column label="分类" width="100">
                    <template slot-scope="scope">
                        <div>{{ typeName(scope.row.type_id) }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="标题" width="320">
                    <template slot-scope="scope">
                        <div class="line_1">{{ scope.row.title }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="课题要求" width="500">
                    <template slot-scope="scope">
                        <div class="line_1">{{ scope.row.conents }}</div>
                    </template>
                </el-table-column>
                <el-table-column prop="teacher.name" label="指导老师" width="120" />
                <el-table-column prop="members" label="人数上限"/>
            </el-table>
        </div>
        <div class="page">
            <el-pagination background layout="prev, pager, next" :total="total" :page-size="pagesize" @current-change="cheangePage"/>
        </div>
    </div>
</template>

<script>
    import { mapState,mapActions } from 'vuex';
    export default {
        name: 'WebTopicList',
        data() {
            return {
                type_id: '',
                year: '',
                page: 0,
                pagesize: 14
            };
        },
        computed: {
            ...mapState('Topic',['typeList','total','yearList','topicList']),
            typeName(){
                return (type_id) => {
                    let type = this.typeList.filter((n) => {
                        return n.id == type_id;
                    })
                    return type[0].name
                }
            }
        },
        watch: {
            typeList(val){
                this.type_id = val[0].id;
            },
            yearList(val){
                this.year = val[0];
            },
            type_id(type_id){
                let { page,pagesize,year } = this;
                this.getTopicList({page,pagesize,year,type_id});
            },
            year(year){
                let { page,pagesize,type_id } = this;
                this.getTopicList({page,pagesize,year,type_id});
            },
        },
        methods: {
            ...mapActions('Topic',['getTypes','getTopicYears','getTopicList']),
            cheangePage(page){
                let { pagesize,type_id,year } = this;
                --page;
                this.getTopicList({page,pagesize,year,type_id});
            }
        },
        mounted(){
            this.getTopicYears();
            this.getTypes();
        }
    };
</script>

<style lang="less" scoped>
    @import "asle/index.less";
    .topic_list {
        .el-select {
            .mar_r(20px);
        }
        .list {
            .marg(10px,0);
        }
        .page {
            .pos_f();
            .pos_rb(20px,20px);
        }
    }
</style>